<?php

	// TITLE: Person_status_type AUTO MODEL
	// FILE: scaffolding/model/person_status_type.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createPersonStatusType = function($con, $personStatusType) {
		$sql = 'INSERT INTO person_status_type (id, title, description, code) VALUES (';
		$sql .= $person_status_type->getId() . ', ';
		$sql .= $person_status_type->getTitle() . ', ';
		$sql .= $person_status_type->getDescription() . ', ';
		$sql .= $person_status_type->getCode() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readPersonStatusType = function($con, $id) {
		$sql = 'SELECT * FROM person_status_type WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$personStatusType = new PersonStatusType();
			$personStatusType->setId(result[0]);
			$personStatusType->setTitle(result[1]);
			$personStatusType->setDescription(result[2]);
			$personStatusType->setCode(result[3]);
		} else {
			$personStatusType = false;
		}
		return $personStatusType;
	};

	$updatePersonStatusType = function($con, $personStatusType) {
		$sql = 'UPDATE person_status_type SET ';
		$sql .= 'id = ' . $person_status_type->getId() . ', ';
		$sql .= 'title = ' . $person_status_type->getTitle() . ', ';
		$sql .= 'description = ' . $person_status_type->getDescription() . ', ';
		$sql .= 'code = ' . $person_status_type->getCode() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deletePersonStatusType = function($con, $id) {
		$sql = 'DELETE FROM person_status_type WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listPersonStatusType = function($con) {
		$sql = 'SELECT * FROM person_status_type';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$personStatusTypes = array();
			while ($result = mysqli_fetch_array($results)) {
				$personStatusType = new PersonStatusType();
				$personStatusType->setId(result[0]);
				$personStatusType->setTitle(result[1]);
				$personStatusType->setDescription(result[2]);
				$personStatusType->setCode(result[3]);
				$personStatusTypes[] = personStatusType;
			}// end while
		} else {
			$personStatusTypes = false;
		}
		return $personStatusTypes;
	};

